<?php
session_start();
header('Content-Type:text/html; charset=utf-8');
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'config.php';
require_once 'dbClasses'.DIRECTORY_SEPARATOR.'dbConn.php';
$db = new dbConn();
$id = $_GET['id'];
$act = $_GET['act'];
$table = empty($_GET['table'])?'content':$_GET['table'];
switch ($act){
	case "shenhe":
		$db->sql = "UPDATE `{$table}` SET `status` = 1 WHERE id = ".$id;
		$db->doExecute();
		echo 1;
		break;
	//加边
	case "isTwoBorder":
		$table = $_GET['table'];
		$db->sql = "UPDATE {$table} SET `isTwoBorder` = (CASE `isTwoBorder` WHEN 0 THEN 1 WHEN 1 THEN 0 ELSE 0 END) WHERE id = ".$id;
		$db->doExecute();
		$db->sql = "SELECT goodsID,publishDate,`isTwoBorder` FROM `{$table}` WHERE id = ".$id;
		$goodsinfo = $db->doResult();
		echo $goodsinfo['isTwoBorder'];
	    break;
	case "isSale":
	    $table = $_GET['table'];
	    $db->sql = "UPDATE {$table} SET `status` = (CASE `status` WHEN 1 THEN 2 WHEN 2 THEN 1 ELSE 0 END) WHERE id = ".$id;
	    $db->doExecute();
	    $db->sql = "SELECT goodsID,publishDate,`status` FROM `{$table}` WHERE id = ".$id;
	    $goodsinfo = $db->doResult();
	    $word=($goodsinfo['status']==1)?'上架':'下架';
	    $db->sql = "INSERT INTO goodschange (changeid,`table`,goodsid,oldsaletime,operate,updater,changetime) VALUES({$id},'{$table}',{$goodsinfo['goodsID']},'{$goodsinfo["publishDate"]}','{$word}','{$_SESSION["userName"]}',".time().")";
	    $db->doExecute();
	    echo $goodsinfo['status'];
	    break;
	case "del":
		//$db->sql = "DELETE FROM content WHERE id = ".$id;
		$sql = $db->sql = "UPDATE `".$table."` SET `status` = 0 , `isDel` = 1 WHERE id = ".$id;
		$db->doExecute();
		$db->sql = "SELECT goodsID,publishDate FROM `".$table."` WHERE id = ".$id;
		$goodsinfo = $db->doResult();
		$db->sql = "INSERT INTO goodschange (changeid,`table`,goodsid,oldsaletime,operate,updater,changetime) VALUES({$id},'{$table}',{$goodsinfo['goodsID']},'{$goodsinfo["publishDate"]}','删除','{$_SESSION["userName"]}',".time().")";
		$db->doExecute();
		echo 1;
		break;
	case "piliangshanchu":
		$ids = trim($_GET['ids'],',');
		$db->sql = "UPDATE `{$table}` SET `status` = 0 , isDel = 1 WHERE id in (".$ids.")";
		$db->doExecute();
		echo 1;
		break;
	//通过ids删除  -----通用
	case "piliangshanchu2byids":
		$ids = trim($_GET['ids'],',');
		$db->sql = "DELETE FROM `{$table}` WHERE id in (".$ids.")";
		$db->doExecute();
		echo 1;
		break;
	case "piliangSetZhuanTi":
	    $ids = trim($_GET['ids'],',');
	    $zhuantiID = $_GET['zhuantiID'];
	    $db->sql = "UPDATE `{$table}` SET zhuantiID = {$zhuantiID} WHERE id in (".$ids.")";
	    $db->doExecute();
	    $rs['ret'] = 1;
	    $db->sql = "SELECT `title` FROM `zz_extend_zhuanti_key` WHERE id = {$zhuantiID}";
	    $rs['title'] = $db->doResultOne();
	    echo json_encode($rs);
	    break;
	case "piliangtongguo":
		if(!empty($_GET['ids'])){
			$ids = trim($_GET['ids'],',');
			$db->sql = "UPDATE `".$table."` SET `status`=1 WHERE id in (".$ids.")";
			$db->doExecute();
			echo 1;
		}else{
			echo -1;
		}
		break;
	case "NPNpiliangtongguo":
		if(!empty($_GET['ids'])){
			$ids = trim($_GET['ids'],',');
			$db->sql = "UPDATE `{$table}` SET `status`=1 WHERE id in (".$ids.")";
			$db->doExecute();
			echo 1;
		}else{
			echo -1;
		}
		break;
	case "ninePointNineDel":
		if(!empty($_GET['id'])){
			$db->sql = "UPDATE ".$table." SET `status`=0,`isDel`=1 WHERE id = ".$_GET['id'];
			$db->doExecute();
			$db->sql = "SELECT goodsID,publishDate FROM `".$table."` WHERE id = ".$id;
			$goodsinfo = $db->doResult();
			$db->sql = "INSERT INTO goodschange (changeid,`table`,goodsid,oldsaletime,operate,updater,changetime) VALUES({$id},'".$table."',{$goodsinfo['goodsID']},'{$goodsinfo["publishDate"]}','删除','{$_SESSION["userName"]}',".time().")";
			$db->doExecute();
			echo 1;
		}else{
			echo -1;
		}
	    break;
	case "VConUnionNpnDel":
	    if(!empty($_GET['id'])){
	        $db->sql = "UPDATE ".$table." SET `status`=0,`isDel`=1 WHERE id = ".$_GET['id'];
	        $db->doExecute();
	        $db->sql = "SELECT goodsID,publishDate FROM `".$table."` WHERE id = ".$id;
	        $goodsinfo = $db->doResult();
	        //
	        $db->sql = "INSERT INTO goodschange (changeid,`table`,goodsid,oldsaletime,operate,updater,changetime) VALUES({$id},'".$table."',{$goodsinfo['goodsID']},'{$goodsinfo["publishDate"]}','删除','{$_SESSION["userName"]}',".time().")";
	        $db->doExecute();
	        echo 1;
	    }else{
	        echo -1;
	    }
	    break;
	case "ninePointNineShenhe":
		if(!empty($_GET['id'])){
			$db->sql = "UPDATE `{$table}` SET `status`=1 WHERE id = ".$id;
			$db->doExecute();
			echo 1;
		}else{
			echo -1;
		}
		break;
	case "NPNListEdit":
		if(!empty($_GET['id'])){
			$db->sql = "SELECT c.*,a.id as aid FROM `{$table}` c LEFT JOIN admin a ON a.userName=c.updater  WHERE c.id = ".$id;
			$info = $db->doResult2();
			
			$info['startTime1']=date("Y-m-d H:i:s" , $info['startTime']);
			$info['endTime1']=date("Y-m-d H:i:s" , $info['endTime']);
			
			//echo json_encode( htmlspecialchars_decode($info) );
			echo json_encode( $info );
		}else{
			echo -1;
		}
	    break;
	case "VConUnionNpnEdit":
	    if(!empty($_GET['id'])){
	        $db->sql = "SELECT c.*,a.id as aid FROM `{$table}` c LEFT JOIN admin a ON a.userName=c.updater  WHERE c.id = ".$id;
	        $info = $db->doResult2();
	        if($table=='priceninepointnine'){
	            $info['startTime1']=date("Y-m-d H:i:s" , $info['startTime']);
	            $info['endTime1']=date("Y-m-d H:i:s" , $info['endTime']);
	        }
	        //echo json_encode( htmlspecialchars_decode($info) );
	        echo json_encode( $info );
	    }else{
	        echo -1;
	    }
	    break;
	case "plsc9p9":
		$ids = trim($_GET['ids'],',');
		$db->sql = "UPDATE `{$table}` SET `status` = 0 , isDel = 1 WHERE id in (".$ids.")";
		$db->doExecute();
		echo 1;
		break;
	case "cuxiaoShenhe":
		if(!empty($_GET['id'])){
			$db->sql = "UPDATE `cuxiao` SET `status`=1 WHERE id = ".$id;
			$db->doExecute();
			echo 1;
		}else{
			echo -1;
		}
		break;
	case "cuxiaoDel":
		if(!empty($_GET['id'])){
			$db->sql = "DELETE FROM `cuxiao` WHERE id = ".$id;
			$db->doExecute();
			echo 1;
		}else{
			echo -1;
		}
		break;
	case "cuxiaotongguo":
		if(!empty($_GET['ids'])){
			$ids = trim($_GET['ids'],',');
			$db->sql = "UPDATE `cuxiao` SET `status`=1 WHERE id in (".$ids.")";
			$db->doExecute();
			echo 1;
		}else{
			echo -1;
		}
		break;
	case "changeSaleStatus":
		if (!empty($_GET['id'])){
			$db->sql = "SELECT onSale FROM cuxiao WHERE id = ".$_GET['id'];
			$salestatus = $db->doResultOne();
			if ($salestatus == 0){$onSale = 1;}
			elseif ($salestatus == 1){$onSale = 0;}
			if ($_GET['saleVal']==$salestatus){
				$db->sql = "UPDATE `cuxiao` SET `onSale`=".$onSale." WHERE id = ".$_GET['id'];
				$db->doExecute();
				echo $salestatus;
			}else{
				echo -1;
			}
		}else{
			echo -1;
		}
		break;
	case "everyClick":
		$key = $_GET["key"];
		$starttime = $_GET['starttime'];
		$endtime = $_GET['endtime'];
		$where = "where name='".$key."' ";
		if( !empty($starttime) ) $where .= "and `date`>='".$starttime."' ";
		if( !empty($endtime) ) $where .= "and `date`<='".$endtime."' ";
		
		$db->sql= "SELECT * FROM keyvaluebydate ".$where." ORDER BY `date` DESC";
		$rs = $db->doResultList2();
		//echo $db->sql;
		echo json_encode($rs);
		//echo $key.'-'.$starttime.'-'.$endtime;
		break;
	case "dataimport":
		echo $_POST['ids'];
		break;
	//是否领取
	case "piliangDelComment2":
		$ids = trim($_GET['ids'],',');
		$db->sql = "DELETE FROM comment2 WHERE id in (".$ids.")";
		$db->doExecute();
		echo 1;
		break;
	case "isreceive":
		$table = ($table=="content")?"auctionsuccess":$table;
		if(!empty($_GET['id'])){
			$db->sql = "UPDATE `".$table."` SET `isreceive`=(CASE `isreceive` WHEN 0 THEN 1 WHEN 1 THEN 0 ELSE 0 END) WHERE id = ".$id;
			$db->doExecute();
			echo 1;
		}else{
			echo -1;
		}
		break;
	case "isInvalid":
		if(!empty($_GET['id'])){
			$db->sql = "UPDATE `".$table."` SET `isInvalid`=(CASE `isInvalid` WHEN 0 THEN 1 WHEN 1 THEN 0 ELSE 0 END) WHERE id = ".$id;
			$db->doExecute();
			echo 1;
		}else{
			echo -1;
		}
		break;
	case "isExceedTheTimeLimit":
		if(!empty($_GET['id'])){
			$db->sql = "UPDATE `".$table."` SET `isExceedTheTimeLimit`=(CASE `isExceedTheTimeLimit` WHEN 0 THEN 1 WHEN 1 THEN 0 ELSE 0 END) WHERE id = ".$id;
			$db->doExecute();
			echo 1;
		}else{
			echo -1;
		}
		break;
	case "pingfen":
		$username = $_GET['username']?$_GET['username']:'';
		$fenshu   = $_GET['fenshu']?$_GET['fenshu']:'';
		$db->sql = "INSERT INTO pingfen(pingfener,be_pingfener,fenshu,pingfen_date) VALUES('{$_SESSION['userName']}','{$username}','{$fenshu}',now())";
		$db->doExecute();
		echo 1;
		break;
	case "changeother":
		if(!empty($_GET['col']) && isset($_GET['val']) && !empty($_GET['id']) ){
			$db->sql = "UPDATE `{$table}` SET {$_GET['col']} = {$_GET['val']} WHERE id = {$_GET['id']} ";
			$db->doExecute();
			echo 1;
		}else{
			echo 0;
		}
		break;
	case "couponstatuschange":
	    $db->sql = "UPDATE `coupon` SET `status` = if(`status`=1,0,1) WHERE id = {$_GET['id']}";
	    $db->doExecute();
	    echo 1;
	    break;
	default:
		echo -1;
		break;
}
return;
?>